<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/
      思路：https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/solution/mian-shi-ti-04-er-wei-shu-zu-zhong-de-cha-zhao-zuo/
     */
    let matrix = [
      [1, 4, 7, 11, 15],
      [2, 5, 8, 12, 19],
      [3, 6, 9, 16, 22],
      [10, 13, 14, 17, 24],
      [18, 21, 23, 26, 30]
    ];
    let target = 5;

    function searchMatrix(matrix, target) {
      let i = matrix.length - 1, j = 0
      while (i >= 0 && j <= matrix[0].length - 1) {
        if (matrix[i][j] > target)  i--
        else if (matrix[i][j] < target)  j++
        else return true
      }
      return false
    }
    console.log(searchMatrix(matrix, target));
  </script>
</body>
</html>